var JVDrawer = new Class({
	options:{
		duration: 400,
		transition: Fx.Transitions.quadOut	
	},
	initialize:function(){
		var options,elements;		
		$each(arguments, function(argument, i){                   
            switch($type(argument)){
                case 'object': options = argument; break;                                
            }
        });            
		this.setOptions(options);	
		this.drawerItem = $$(this.options.draweritem);			
		this.fx = new Fx.Elements(this.drawerItem, {wait: false, duration: this.options.duration, transition: this.options.transition});		
		if(this.options.eventtype == 1){
			eventtype = 'mouseenter';
		} else {
			eventtype ='click';
		}
		this.drawerItem.each(function(el,i){
			el.addEvent(eventtype, function(e){
				new Event(e).stop();				
				if(this.options.isstyle == 'default_v'){
					this.verticalDrawer(i);
				} else if(this.options.isstyle == 'photo_h'){
					this.photoHorDrawer(i);
				} else {
					this.photoVerDrawer(i);
				}					
			}.bind(this));			
		}.bind(this));
			
	},
	photoVerDrawer:function(num){
		if($type(num) == 'number'){
			var obj = {};
            for(i=0;i<num;i++){
             var top_height = -this.options.itemshift + i*this.options.otheritem.toInt();           
             obj[i] = {'top':top_height};
             this.drawerItem[i].removeClass('active');  
            }
            top_height = num*this.options.otheritem.toInt();
            this.drawerItem[num].addClass('active');            
            obj[num] = {'top':top_height};
            for(i=num+1;i<this.drawerItem.length -1;i++){
                top_height = top_height+this.options.otheritem.toInt();
                obj[i] = {'top':top_height};
                this.drawerItem[i].removeClass('active');                           
            }
            if(num !=this.drawerItem.length -1){
             top_height = (this.drawerItem.length -1)*this.options.otheritem.toInt(); 
             obj[this.drawerItem.length -1] = {'top':top_height};
             this.drawerItem[this.drawerItem.length -1].removeClass('active');       
            } 	
		}
		this.fx.start(obj);
	},
	verticalDrawer:function(num){
		if($type(num) == 'number'){
			var obj = {};
			for(i=0;i<num;i++){
			 var top_height = -this.options.itemshift + i*this.options.otheritem.toInt();			
			 obj[i] = {'top':top_height};
			 this.drawerItem[i].removeClass('active');	
			}
			top_height = num*this.options.otheritem.toInt();
			this.drawerItem[num].addClass('active');			
			obj[num] = {'top':top_height};
			for(i=num+1;i<this.drawerItem.length -1;i++){
			 	top_height = top_height+this.options.otheritem.toInt();
		        obj[i] = {'top':top_height};
		        this.drawerItem[i].removeClass('active');   	 				 	
			}
			if(num !=this.drawerItem.length -1){
			 top_height = (this.drawerItem.length -1)*this.options.otheritem.toInt(); 
			 obj[this.drawerItem.length -1] = {'top':top_height};
			 this.drawerItem[this.drawerItem.length -1].removeClass('active');       
			} 
		}		
		this.fx.start(obj);
	},
	photoHorDrawer:function(num){
		if($type(num) == 'number'){
			var obj = {};
			for(i=0;i<num;i++){
				var left_height = -this.options.itemshift + i*this.options.otheritem.toInt();
				obj[i] = {'left':left_height};
			}
			left_height = num*this.options.otheritem.toInt();
			obj[num] = {'left':left_height};
			for(i=num+1;i<this.drawerItem.length -1;i++){
                left_height = left_height+this.options.otheritem.toInt();
                obj[i] = {'left':left_height};                        
            }
            if(num !=this.drawerItem.length -1){
             left_height = (this.drawerItem.length -1)*this.options.otheritem.toInt(); 
             obj[this.drawerItem.length -1] = {'left':left_height};                
            } 
		}
		this.fx.start(obj);
	}		
}
)
JVDrawer.implement(new Options);
JVDrawer.implement(new Events);
